#include <QtCore/QCoreApplication>
#include <QtCore/QFileSystemWatcher>
#include <QtCore/QStringList>

#include "devicenotifier.h"

QFileSystemWatcher *watcher = 0;

DeviceNotifier *DeviceNotifier::pInstance = 0;

DeviceNotifier *DeviceNotifier::instance ()
{
	if (!pInstance) {
		pInstance = new DeviceNotifier (QCoreApplication::instance ());
	}

	return pInstance;
}

DeviceNotifier::DeviceNotifier (QObject *parent)
	: QObject (parent)
{
	if (!watcher) {
		watcher = new QFileSystemWatcher ();
		watcher->addPath ("/dev");
		connect (watcher, SIGNAL (directoryChanged (QString)),
				 this, SIGNAL (deviceListChanged ()));
	}
}

DeviceNotifier::~DeviceNotifier ()
{
	if (pInstance == this) {
		if (watcher) {
			watcher->deleteLater();
		}
		pInstance = 0;
	}
}


